<template>
	<div class=" person_info">
		<van-nav-bar title="资料编辑" left-arrow right-text="完成" @click-left="$router.history.go(-1)" @click-right="onClickRight">
			<span slot='left' class="topleftIcon"><img src='../../../public/images/qt_75.png'/></span>
    	</van-nav-bar>	
		<van-cell title="头像" value="头像">
			<td-upload @upload-img="headPortrait" class="imgBox" >
					<img :src="info.userPhoto" :style="{display:info.userPhoto?'block':'none'}">
			</td-upload>
				<!-- <div class="van-uploader imgBox"><input type="file" accept="image/png,image/jpg,image/jpeg" @change="change($event)" class="van-uploader__input">
					<img :src="info.userPhoto" :style="{display:info.userPhoto?'block':'none'}">
				</div> -->
			

		</van-cell>
		<van-cell title="姓名" value="沈佳宜" class="values">
			<input class="name" :placeholder="info.userName?info.userName:'暂未设置昵称'" v-model="info.userName"/>
		</van-cell>
		<van-cell title="学号" value="54545121" class="values">
			<input class="name" :placeholder="info.campusCode?info.campusCode:'暂未设置学号'" v-model="info.campusCode"/>
		</van-cell>
		<van-cell title="性别">
			<van-radio-group v-model="info.gender" class="r">
			  <van-radio name="1" class="radio">男</van-radio>
			  <van-radio name="0" class="radio">女</van-radio>
			</van-radio-group>
		</van-cell>
		<van-cell title="生日" :value="birth" is-link @click='timeShow=true'></van-cell>
		<!-- <van-cell title="收货地址" value="54545121">
			<input class="name" :placeholder="info.address?info.address:'暂未设置地址'" v-model="info.address"/>
		</van-cell> -->




		<van-actionsheet v-model="timeShow" title="日期">
			<van-datetime-picker
				v-model="currentDate"
				type="date"
				:min-date="minDate"
				:max-date="maxDate"
				@confirm='timeChoose'
				@cancel='timeShow=false'
			/>
		</van-actionsheet>
	</div>
</template>

<script>
	import storage from '@/common/store'
	export default {
		data() {
			return {
				info:{},
				minDate:new Date('1990'),
				maxDate:new Date(),
				currentDate: new Date(),
				timeShow:false,
				birth:'',
			}
		},
		created() {
			this.getMessage();
		},
		methods: {
			// change( event ) {
			// 	let that=this;
			// 	console.log(event)
			// 	this.clip(event , {
			// 		resultObj : '',
			// 		aspectRatio : 1
			// 	},function(data){
			// 		if(data) that.$set(that.info,'userPhoto',data);
			// 	})
			// },
			getMessage(){
				this.$get(this.$api.user.info).then(data=>{
					if(!data.data.userPhoto) data.data.userPhoto=require('../../../public/images/avtor.png');
					data.data.gender=String(data.data.gender);
					this.info=data.data;
					this.birth=this.Convert_yearIso(data.data.birth)
					this.info.birth=this.isoSjc(data.data.birth)
					storage.setItem('userInfo',this.info);
					console.log(this.info);
				})
			},
			onClickRight(){
				let that=this;
				if(!this.info.userName){
					this.$toast.fail('请先输入姓名');
					return;
				};
				var parm={
					userName:this.info.userName,
					userPhoto:this.info.userPhoto,
					gender:this.info.gender,
					birth:this.info.birth
				};
				this.$post(this.$api.user.update,parm).then(data=>{
					that.$toast.success({message:'修改成功',duration:500,onClose:function(){
						storage.setItem('userInfo',that.info);
						that.$router.push({path:'person'})
					}});
				})

			},
			headPortrait(e){
				this.$set(this.info,'userPhoto',e);
				console.log(this.info)
			},
			 timeChoose(e){
				console.log(e);
				let data = Date.parse(new Date(e));
				this.info.birth =data;
				this.birth =this.Convert_year(data);
				this.timeShow=false;
			}
		}
	}
</script>
<style scoped="scoped">
	.person_info{height: 100vh;}
	.radio{float: left;margin-left: 0.2rem;}
	.imgBox img{width:30px;height:30px;}
	.imgBox{width:30px;height:30px;border-radius:50%;overflow:hidden;display:inline-block;box-sizing:border-box}
	.name{border:0;width: 70%;float: right;text-align: right;padding-right: 10px;}
</style>
